package com.rcklos.bottomnavgationdemo.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.rcklos.bottomnavgationdemo.R;

public class Nav1Activity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {

    RelativeLayout layout1, layout2, layout3;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nav1);
        layout1 = findViewById(R.id.layout_nav1_tab1);
        layout2 = findViewById(R.id.layout_nav1_tab2);
        layout3 = findViewById(R.id.layout_nav1_tab3);

//        ((RadioGroup)findViewById(R.id.nav1_rg)).setOnCheckedChangeListener(this);
        ((RadioButton)findViewById(R.id.nav1_rb_1)).setOnCheckedChangeListener(this);
        ((RadioButton)findViewById(R.id.nav1_rb_2)).setOnCheckedChangeListener(this);
        ((RadioButton)findViewById(R.id.nav1_rb_3)).setOnCheckedChangeListener(this);

        ((Button)findViewById(R.id.btn_nav1_1)).setOnClickListener(this);
        ((Button)findViewById(R.id.btn_nav1_2)).setOnClickListener(this);
        ((Button)findViewById(R.id.btn_nav1_3)).setOnClickListener(this);
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if(b){
            layout1.setVisibility(View.GONE);
            layout2.setVisibility(View.GONE);
            layout3.setVisibility(View.GONE);
            switch (compoundButton.getId()){
                case R.id.nav1_rb_3:
                    layout3.setVisibility(View.VISIBLE);
                    break;
                case R.id.nav1_rb_2:
                    layout2.setVisibility(View.VISIBLE);
                    break;
                case R.id.nav1_rb_1:
                default:
                    layout1.setVisibility(View.VISIBLE);
                    break;
            }
        }
    }

    @Override
    public void onClick(View view) {
        Toast.makeText(this, ((Button)view).getText(), Toast.LENGTH_SHORT)
                .show();
    }
}
